<script lang="ts" setup>
import AuthorFocus from "@/components/icon/AuthorFocus.vue";
import { onMounted, ref } from "vue";
import { Api } from "@/apis";
import { authorStoriesStore,homeStoriesStore } from "@/store";
import { AuthorDetail } from "@/typing";
import { useRouter } from "vue-router";

let authorList = ref<Array<AuthorDetail>>();
const router = useRouter()
const authorStore = authorStoriesStore();
const {updateAuthorData } = authorStore;

const store = homeStoriesStore();
const { updateIsDiscoverShow } = store;

onMounted(async () => {
    const data = await Api.getHotAuthorList();
    authorList.value = data.data.data;

})

function goToAuthorDetail(list: AuthorDetail) {
    updateIsDiscoverShow(true);
    updateAuthorData(list)
    let id = list.user_id;
    router.push({ name: 'author-detail', query: { id } })
}

</script>

<template>
    <div class="px-8 pb-32 pt-3">
        <div class="text-3xl my-5">热门作者</div>
        <div v-for="(l, i) in authorList" :key="i" class="flex items-center mb-10">
            <img class="w-24 h-24 mr-5 rounded-full" :src="l.web_url" alt="img">
            <div class="w-3/5" @click="goToAuthorDetail(l)">
                <div class="search-title text-2xl mb-3">{{ l.user_name }}</div>
                <div class="text-gray-400 search-title">{{ l.desc }}</div>
            </div>
            <div class="w-1/5 text-center">
                <AuthorFocus :list="l" :type="0" />
            </div>
        </div>
    </div>
</template>

